import 'package:flutter/material.dart';
import 'package:getx_scaffold/common/index.dart';

class CustomBottomBar extends StatelessWidget {
  final List<BottomNavigationBarItem> items;
  final Color unselectedItemColor;
  final Color selectedItemColor;
  final int iconSize;
  final int selectedFontSize;
  final int unselectedFontSize;
  final BottomNavigationBarType type;
  final int currentIndex;
  final Null Function(dynamic index) onTap;

  const CustomBottomBar({
    super.key,
    required this.items,
    required this.unselectedItemColor,
    required this.selectedItemColor,
    required this.iconSize,
    required this.selectedFontSize,
    required this.unselectedFontSize,
    required this.type,
    required this.currentIndex,
    required this.onTap,
  });

  @override
  Widget build(BuildContext context) {
    return SafeArea(
      child: Container(
        width: double.infinity,
        height: 58.h,
        decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.only(
            topLeft: Radius.circular(16.r),
            topRight: Radius.circular(16.r),
          ),
          boxShadow: [
            BoxShadow(
              color: const Color(0x1A004080),
              // 对应android:shadowColor="#1a004080"
              offset: Offset(0, 2.w),
              // 对应shadowDx=0, shadowDy=2
              blurRadius: 20.w,
              // Flutter中需要设置模糊半径
              spreadRadius: 0, // 阴影扩散半径
            ),
          ],
        ),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceAround,
          children: [
            for (int i = 0; i < items.length; i++)
              InkWell(
                onTap: () => onTap(i),
                child: Item(
                  item: items[i],
                  isActive: currentIndex == i,
                  unselectedItemColor: unselectedItemColor,
                  selectedItemColor: selectedItemColor,
                ),
              )
          ],
        ),
      ),
    );
  }
}

class Item extends StatelessWidget {
  const Item(
      {super.key,
      required this.item,
      required this.isActive,
      required this.unselectedItemColor,
      required this.selectedItemColor});

  final BottomNavigationBarItem item;
  final bool isActive;
  final Color unselectedItemColor;
  final Color selectedItemColor;

  @override
  Widget build(BuildContext context) {
    return Container(
      padding: EdgeInsets.symmetric(horizontal: 30.w),
      child: Column(
        mainAxisSize: MainAxisSize.max,
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          if (isActive) item.activeIcon else item.icon,
          Text(
            item.label ?? '',
            style: TextStyle(
              color: isActive ? selectedItemColor : unselectedItemColor,
              fontSize: 10.sp,
              fontFamily: 'Inter',
              fontWeight: FontWeight.w600,
            ),
          )
        ],
      ),
    );
  }
}
